package com.dao;

import com.bean.car;
import com.dao.baseDao;
import com.dao.carDao;

import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.List;

public class test {

    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement pstmt = null;//预处理对象
        int rs;//结果对象
        boolean flag = false;//用来判断是否登入成功的标志
        int id = 1;
        String pwd ="123456";
        String url = "jdbc:mysql://localhost:3306/rg56?useUnicode=true&characterEncoding=utf8";
        //数据库的用户名一般为 root
        String user = "root";
        //数据库的密码
        String password = "Wzh201227";
        try {
            //本项目用的是MySQL
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(url, user, password);
            //sql语句 stuno 为表名
            String sql = "INSERT INTO stuno(id, name, password) VALUES (?, ?, ?)";
            System.out.println(sql);
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, "8");
            pstmt.setString(2, "宝马");
            pstmt.setString(3, "宝马");
            rs = pstmt.executeUpdate();
            if (rs > 0) {
                flag = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
        System.out.println(flag);
    }
}
